package com.stox.client.api.core;

import java.util.HashSet;
import java.util.Set;

import com.stox.services.core.subscription.SubscriptionManager;
import com.stox.shared.core.model.intf.Callback;


public class WebSocketClient {

	public static final WebSocketClient INSTANCE = new WebSocketClient();
	
	private final Set<Callback<String,Boolean>> callbacks = new HashSet<>();
	
	private WebSocketClient() {
		
	}
		
	public void addCallback(Callback<String,Boolean> callback){
		callbacks.add(callback);
	}
	
	public void removeCallback(Callback<String,Boolean> callback){
		callbacks.remove(callback);
	}
	
	
	public void sendMessage(String message) {
		SubscriptionManager.INSTANCE.onMessage(message);
	}
	
	public void onMessage(String message) {
		for(Callback<String,Boolean> callback : callbacks){
			callback.execute(message);
		}
	}
		
}
